package bairui.international.weixin.portal.miniapp.controller.address.address;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianjing.sh.spring.web.controller.base.action.Action;
import com.lianjing.sh.spring.web.controller.enhance.output.FomatOutput;

import bairui.international.model.domain.jpa.TB_Address;
import bairui.international.model.domain.jpa.TB_Town;
import bairui.international.model.domain.jpa.TB_User;
import bairui.international.service.Service_Address;
import bairui.international.service.Service_User;
import lombok.Getter;
import lombok.Setter;

/**
 *
 * 编辑
 *
 * @generated
 * 
 * @see STest_C_Address_Edit_Post 测试
 *
 */
@Controller
public class C_Address_Edit_Post
 extends SC_Address_Edit_Post 
{
	
	@Autowired private Service_Address service_Address;
	@Autowired private Service_User service_User;
	
	/**
	 * Post请求
	 */
	@Action(Post.class)
	@PutMapping(Post.RequestMappingValue)
	public @FomatOutput @ResponseBody Object post(
		ModelMap map, HttpServletRequest request, 
		@PathVariable(name=Post.PathVariableName.Id) long id,
		@RequestParam String skey,
		@RequestBody Input input
	) throws Exception {
		TB_User user = service_User.findOne(it->it.skey.eq(skey));
		TB_Address bean = service_Address.edit(
				id, 
				user,
				input.getUsername(), 
				input.getPhone(), 
				new TB_Town(input.getTownId()), 
				input.getDetailAddress(),
				input.getDefaultFlag()
			);
		return bean.getId();
	}
	
	private static class Input {
		@Getter @Setter private String username;
		@Getter @Setter private String phone;
		@Getter @Setter private String detailAddress;
		@Getter @Setter private Long amount;
		@Getter @Setter private Long townId;
		@Getter @Setter private Boolean defaultFlag;
	}
	

}
